import * as tf from "@tensorflow/tfjs";
import * as mobilenet from "@tensorflow-models/mobilenet";
import { useEffect, useRef } from "react";
import { file2img } from "./utils";

export default function () {
    const imgRef = useRef(null);
    async function start() {
    }
    async function predict(file, v) {
        var imgBlob = URL.createObjectURL(file.target.files[0]);
        const img = document.createElement("img");
        img.src = imgBlob;
        const model = await mobilenet.load(); // 加载mobilenet模型
        // 预测单张图片的结果
        const predictions = await model.classify(img);
        console.log(predictions)
    };
    useEffect(() => {
        start();
        // const imgDom = imgRef.current;
        // imgDom.onchange = predict;
    }, [])
    return <div>
        <input ref={imgRef} type="file" onChange={predict} />
        {/* <img src="https://p1.ssl.qhimgs1.com/sdr/400__/t0482f0cc4e1ba96ba7.jpg" ref={imgRef} /> */}
        {/* <button onClick={predict}>开始</button> */}
    </div>
}